import React from "react";
import { /* Popconfirm,  */ Divider } from "antd";
import Link from "umi/link";
import queryString from "query-string";
import { getTableProps } from "components/searchTable/SearchTable.jsx";
import {
  getMenuRouter,
  getPageOperate,
} from "../../../../components/layouts/menuFn";

export default class Base extends React.Component {
  getMenuRouter = getMenuRouter.bind(this);

  getPageOperate = getPageOperate.bind(this);

  getOprateDisable = (type) => {
    const {
      location: { pathname = "" },
      menuDataList,
      resourceList,
    } = this.props;
    const res = this.getPageOperate(type, pathname, menuDataList, resourceList);
    return res;
  };

  getFormConfig = () => {
    return [
      { label: "流程名称", key: "modelName" },
      { label: "流程单号", key: "serialNum" },
    ];
  };

  getTableColumns = () => {
    return [
      {
        title: "序号",
        dataIndex: "processInstanceId",
        render: (value, record, index) => {
          const {
            page: { pageNum, pageSize },
          } = this.state;
          return (pageNum - 1) * pageSize + index + 1;
        },
      },
      { title: "流程名称", dataIndex: "modelName" },
      { title: "流程单号", dataIndex: "serialNum" },
      { title: "当前环节", dataIndex: "taskName" },
      {
        title: "状态",
        dataIndex: "status",
        render: (value) => (value === "TODO" ? "待处理" : "已完成"),
      },
      { title: "申请时间", dataIndex: "applyTime" },
      { title: "申请人", dataIndex: "applyUserName" },
      {
        title: "操作",
        dataIndex: "claim",
        render: (value, record) => {
          const {
            // assignee,
            // taskId,
            // formKey,
            // processDefinitionId,
            canRemind,
            canRecall,
            processInstanceId,
          } = record; // 是否当前任务处理 1:是，0:否
          // const taskhandle = this.getOprateDisable("taskhandle");
          // const taskclaim = this.getOprateDisable("claim");
          return (
            <>
              <Link
                to={{
                  pathname: "/taskcenter/detail",
                  search: queryString.stringify({
                    processInstanceId: record.processInstanceId,
                    actype: "apply",
                  }),
                }}
              >
                详情
              </Link>
              {canRemind && (
                <>
                  <Divider type="vertical" />
                  <a
                    onClick={(e) => {
                      e.preventDefault();
                      this.handlePushDeal(processInstanceId);
                    }}
                  >
                    催办
                  </a>
                </>
              )}
              {canRecall && (
                <>
                  <Divider type="vertical" />
                  <a
                    onClick={(e) => {
                      e.preventDefault();
                      this.handleReturnBackVisible(true, processInstanceId);
                    }}
                  >
                    撤回
                  </a>
                </>
              )}
              {/* {(assignee === 1 && value === true && taskhandle && (
                <>
                  <Divider type="vertical" />
                  <Link
                    to={{
                      pathname: "/taskcenter/deal",
                      search: queryString.stringify({
                        taskId,
                        processDefinitionId,
                        formKey,
                      }),
                    }}
                  >
                    处理
                  </Link>
                </>
              )) ||
                null} */}
              {/* {(value === false && taskclaim && (
                <>
                  <Divider type="vertical" />
                  <Popconfirm
                    placement="left"
                    title={`确定签收：${record.modelName}?`} // `
                    onConfirm={() => {
                      this.handleTaskclaim(record);
                    }}
                    okText="确定"
                    cancelText="取消"
                  >
                    <a
                      onClick={(e) => {
                        e.preventDefault();
                      }}
                    >
                      签收
                    </a>
                  </Popconfirm>
                </>
              )) ||
                null} */}
            </>
          );
        },
      },
    ];
  };

  getAntTableProps = () => {
    const {
      page: { pageNum, pageSize },
    } = this.state;
    const { applyData, loading } = this.props;
    const { datas = [], totalCount } = applyData;
    return getTableProps({
      rowKey: "processInstanceId",
      columns: this.getTableColumns(),
      dataSource: datas,
      loading:
        loading.effects["FlowHandle/getProApplyNew"] ||
        loading.effects["FlowHandle/handleTaskclaim"],
      pagination: {
        current: pageNum,
        pageSize,
        total: totalCount,
        onChange: this.handlePageChange,
        onShowSizeChange: this.handlePageChange,
      },
    });
  };
}
